package com.yike.order.controller;

import com.yike.common.api.Add;
import com.yike.common.api.ApiResult;
import com.yike.common.base.BaseController;
import com.yike.common.enums.OperationLogType;
import com.yike.common.log.OperationLog;
import com.yike.common.pagination.Paging;
import com.yike.order.param.*;
import com.yike.order.service.PlatformOrderService;
import com.yike.order.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 平台订单
 *
 * @author Sakura
 * @since 2024-11-01
 */
@Slf4j
@RestController
@RequestMapping("/platform/order")
@Api(value = "平台订单API", tags = {"平台订单管理"})
public class PlatformOrderController extends BaseController {

    @Autowired
    private PlatformOrderService platformOrderService;

    @PostMapping("/getPageList")
    //@OperationLog(name = "订单分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "订单分页列表", response = PlatformOrderVo.class)
    public ApiResult<Paging<PlatformOrderVo>> getOrderList(@Validated @RequestBody PlatformOrderPageParam platformOrderPageParam) throws Exception {
        Paging<PlatformOrderVo> paging = platformOrderService.getOrderList(platformOrderPageParam);
        return ApiResult.ok(paging);
    }

    @GetMapping("/info/{orderNo}")
    //@OperationLog(name = "订单详情", type = OperationLogType.INFO)
    @ApiOperation(value = "订单详情", response = PlatformOrderInfoVo.class)
    public ApiResult<PlatformOrderInfoVo> getOrderInfo(@PathVariable("orderNo") String orderNo) throws Exception {
        PlatformOrderInfoVo platformOrderInfoVo = platformOrderService.getOrderInfo(orderNo);
        return ApiResult.ok(platformOrderInfoVo);
    }

    @PostMapping("/refund")
    @OperationLog(name = "订单退款", type = OperationLogType.ADD)
    @ApiOperation(value = "订单退款", response = ApiResult.class)
    public ApiResult<Boolean> refund(@Validated(Add.class) @RequestBody RefundOrderParam refundOrderParam) throws Exception {
        boolean flag = platformOrderService.refund(refundOrderParam);
        return ApiResult.result(flag);
    }

    @GetMapping("/queryStatus/{orderNo}")
    //@OperationLog(name = "订单状态查询", type = OperationLogType.ADD)
    @ApiOperation(value = "订单状态查询", response = ApiResult.class)
    public ApiResult<Integer> queryStatus(@PathVariable("orderNo") String orderNo) throws Exception {
        Integer status = platformOrderService.queryStatus(orderNo);
        return ApiResult.ok(status);
    }

    @GetMapping("/refundInfo/{refundNo}")
    //@OperationLog(name = "退款详情", type = OperationLogType.INFO)
    @ApiOperation(value = "退款详情", response = RefundInfoVo.class)
    public ApiResult<RefundInfoVo> getRefundInfo(@PathVariable("refundNo") String refundNo) throws Exception {
        RefundInfoVo refundInfoVo = platformOrderService.getRefundInfo(refundNo);
        return ApiResult.ok(refundInfoVo);
    }

}

